package com.example.springbasic.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
@Component
public class Notice {

    @Pointcut("execution(public * com.example.springbasic.service.*.*(..))")
    public void pc() {
    }

    @Before("pc()")
    public void before() {
        log.error("---before---");
    }

    @After("pc()")
    public void after() {
        log.error("---after---");
    }

    @AfterReturning(value="pc()",returning="result")
    public void afterReturning(JoinPoint joinPoint, Object result){
        log.error("---afterReturning---");
    }
    @AfterThrowing(value="pc()",throwing="e")
    public void afterThrowing(JoinPoint joinPoint, Exception e){
        log.info("---afterThrowing---");
    }

    @Around("pc()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        log.info("---before around---");
        Object object = pjp.proceed();
        log.info("---after around---");
        return object;
    }
}
